<?php
 require_once 'DB.class.php';  
   
 class Pro {  
   
     public $bid_price;  
     private $pro_id;  
     private $memid;  
     private $pro_name; 
     private $pro_prince; 
     private $pro_desc;
     private $categories_id;
     private $price_bid;
     private $pro_image1;
     private $pro_image2;
     private $pro_image3;
     private $pro_image4;
     private $pro_image5;
     private $soldfor;
     private $bid_used;

     //Constructor is called whenever a new object is created.  
     //Takes an associative array with the DB row as an argument.  
     function __construct($data) {  
         $this->memid = (isset($data['memid'])) ? $data['memid'] : "";  
         $this->bid_price = (isset($data['bid_price'])) ? $data['bid_price'] : "";  
         $this->pro_id = (isset($data['pro_id'])) ? $data['pro_id'] : "";  
         $this->pro_name = (isset($data['pro_name'])) ? $data['pro_name'] : "";  
         $this->pro_desc = (isset($data['pro_desc'])) ? $data['pro_desc'] : "";  
         $this->pro_prince = (isset($data['pro_prince'])) ? $data['pro_prince'] : "";  
         $this->categories_id = (isset($data['categories_id'])) ? $data['categories_id'] : "";  
         $this->price_bid = (isset($data['price_bid'])) ? $data['price_bid'] : "";  
         $this->pro_image1 = (isset($data['pro_image1'])) ? $data['pro_image1'] : "";  
         $this->pro_image2 = (isset($data['pro_image2'])) ? $data['pro_image2'] : "";  
         $this->pro_image3 = (isset($data['pro_image3'])) ? $data['pro_image3'] : "";  
         $this->pro_image4 = (isset($data['pro_image4'])) ? $data['pro_image4'] : "";  
         $this->pro_image5 = (isset($data['pro_image0'])) ? $data['pro_image0'] : ""; 
         $this->soldfor = (isset($data['soldfor'])) ? $data['soldfor'] : ""; 
         $this->bid_used = (isset($data['bid_used'])) ? $data['bid_used'] : ""; 
     }  
   
     public function save() {  
         //create a new database object.  
         $db = new DBBase();  

         //if the user is being registered for the first time. 
             $data = array( 
                 "bid_price" => "'$this->bid_price'",  
                 "pro_id" => "'$this->pro_id'",  
                 "memid" => "'$this->memid'"
             );     
             $this->memid = $db->insert($data, 'tblbidhistory'); 
             
             $data1 = array( 
                 "price_bid" => "'$this->price_bid'",  
                 "pro_id" => "'$this->pro_id'"  
             );  
              $db->update($data1, 'tblproduct', 'pro_id = '.$this->pro_id);  
    }  
    public function insertPro(){
        $db = new DBBase();
        $data = array( 
                 "pro_name" => "'$this->pro_name'",  
                 "pro_id" => "'$this->pro_id'",
                 "pro_prince" => "'$this->pro_prince'",
                 "pro_image1" => "'$this->pro_image1'",
                 "pro_image2" => "'$this->pro_image2'",
                 "pro_image3" => "'$this->pro_image3'",
                 "pro_image4" => "'$this->pro_image4'",
                 "pro_image5" => "'$this->pro_image5'",
                 "pro_desc" => "'$this->pro_desc'",
                 "categories_id" => "'$this->categories_id'"
             );  
        $this->pro_id = $db->insert($data, 'tblproduct');
    }	
    public function completeBid(){
        $db = new DBBase();
        $data = array( 
                 "pro_id" => "'$this->pro_id'",  
                 "memid" => "'$this->memid'",
                 "soldfor" => "'$this->soldfor'",
                 "bid_used" => "'$this->bid_used'",
                 "sold_date" => "'".date("Y-m-d H:i:s",time())."'"

             );  
        $db->insert($data, 'tblmemberwon');
        
        $data1 = array( 
                 "status" => "0",  
                 "pro_id" => "'$this->pro_id'"  
             );  
        $db->update($data1, 'tblproduct', 'pro_id = '.$this->pro_id); 
    }
}
 
 ?>  